package cc.realxyq.demo.component;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor;

/**
 * @author kwhan
 * @date 2022年01月08日 21:17
 */
@Slf4j
public class MyBeanPostProcessor implements BeanPostProcessor, DestructionAwareBeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.contains("red")) {
            log.error("我是通过自定义BeanPostProcessor的 postProcessBeforeInitialization 初始化的数据......");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(beanName.contains("red")) {
            log.error("我是通过自定义BeanPostProcessor的 postProcessAfterInitialization 初始化的数据......");
        }
        return bean;
    }

    @Override
    public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
        if(beanName.contains("red")) {
            log.error("我是通过自定义BeanPostProcessor的 postProcessBeforeDestruction 完成清理工作......");
        }
    }
}
